<?php

	class UserModel extends Model{
		public function UserAction(){
			$strip = 5;
			$page = isset($_GET['page'])?$_GET['page']:0;
			$start = $page*$strip;

			$sql = "select * from user where status = 0 order by reputation limit $start,$strip";
	        $data = $this->link->selectDB($sql);
			
	        echo json_encode($data);
		}
		public function PagerAction(){
			$strip = 5;
			$sql = "select count(id) from user where status = 0";
			$data = $this->link->selectDB($sql);
			$row = ceil($data[0]['count(id)']/$strip);
			echo json_encode($row);
		}
		public function userBanAction(){
			$id = isset($_GET['id'])?$_GET['id']:0;
			$sql = "update user set status = 1 where id = $id";
			$data = $this->link->query($sql);
			echo json_encode($data);
		}
		public function userBlackAction(){
			$strip = 5;
			$page = isset($_GET['page'])?$_GET['page']:0;
			$start = $page*$strip;

			$sql = "select * from user where status = 1 limit $start,$strip";
	        $data = $this->link->selectDB($sql);
			
	        echo json_encode($data);
		}
		public function PagerBalckAction(){
			$strip = 5;
			$sql = "select count(id) from user where status = 1";
			$data = $this->link->selectDB($sql);
			$row = ceil($data[0]['count(id)']/$strip);
			echo json_encode($row);
		}
		public function userNoBanAction(){
			$id = isset($_GET['id'])?$_GET['id']:0;
			$sql = "update user set status = 0 where id = $id";
			$data = $this->link->query($sql);
			echo json_encode($data);
		}
		public function searchAction(){
			$strip = 5;
			$page = isset($_GET['page'])?$_GET['page']:0;
			$start = $page*$strip;

			$searchInfo = isset($_GET['searchInfo'])?$_GET['searchInfo']:'';
			$sql = "select * from user where username like '%$searchInfo%' and status = 0 limit $start,$strip";
			$data = $this->link->selectDB($sql);
			echo json_encode($data);
		}
		public function searchPagerAction(){
			$strip = 5;
			$searchInfo = isset($_GET['searchInfo'])?$_GET['searchInfo']:'';
			$sql = "select count(id) from user where username like '%$searchInfo%' and status = 0";
			$data = $this->link->selectDB($sql);
			$row = ceil($data[0]['count(id)']/$strip);
			echo json_encode($row);
		}
		public function searchBlackAction(){
			$strip = 5;
			$page = isset($_GET['page'])?$_GET['page']:0;
			$start = $page*$strip;

			$searchInfo = isset($_GET['searchInfo'])?$_GET['searchInfo']:'';
			$sql = "select * from user where username like '%$searchInfo%' and status = 1 limit $start,$strip";
			$data = $this->link->selectDB($sql);
			echo json_encode($data);
		}
		public function searchPagerBlackAction(){
			$strip = 5;
			$searchInfo = isset($_GET['searchInfo'])?$_GET['searchInfo']:'';
			$sql = "select count(id) from user where username like '%$searchInfo%' and status = 1";
			$data = $this->link->selectDB($sql);
			$row = ceil($data[0]['count(id)']/$strip);
			echo json_encode($row);
		}
	}